package com.nineclock.system.controller;

import com.nineclock.common.aliyun.sms.SmsUtils;
import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.system.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangchao
 * @create 2022-01-13 19:44
 **/
@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

    /**
     * 发送短信验证码
     * @param mobile 发送的电话
     * @param type
     * | 1    | 登录         |
     * | 2    | 注册         |
     * | 3    | 更换主管理员 |
     * | 4    | 重置密码     |
     */
    @GetMapping("/code")
    public Result sendSMSMessage(@RequestParam("mobile") String mobile, @RequestParam("type") String type){

        //发送短信
        smsService.sendSMSMessage(mobile,type);

        return Result.success();

    }

    /**
     * 验证码校验
     * @param checkCode 验证码
     * @param mobile 手机号
     * @param type 验证码类型
     * @return
     */
    @GetMapping("/verify")
    public Result verifySMSMessage(@RequestParam("checkcode") String checkCode,
                                   @RequestParam("mobile") String mobile,
                                   @RequestParam("type") String type){

        smsService.verifySMSMessage(checkCode,mobile,type);

//        return Result.diyResult(true, ResponseEnum.SUCCESS.getCode(),"验证码校验通过",Boolean.TRUE);
        return Result.success(Boolean.TRUE);

    }

}
